﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WP7Contrib.View.Controls.Extensions
{
    public static class FrameworkElementExtensions
    {
        /// <summary>
        /// Shows the element, playing a storyboard if one is present
        /// </summary>
        /// <remarks>
        /// see: http://www.scottlogic.co.uk/blog/colin/2009/09/helpful-extension-methods-for-show-hide-animations-in-silverlight/
        /// </remarks>
        public static void Show(this FrameworkElement element)
        {
            string animationName = element.Name + "ShowAnim";

            // check for presence of a show animation
            Storyboard showAnim = element.Resources[animationName] as Storyboard;
            if (showAnim != null)
            {
                showAnim.Begin();
            }
            else
            {
                element.Visibility = Visibility.Visible;
            }
        }

        /// <summary>
        /// Hides the element, playing a storyboard if one is present
        /// </summary>
        /// <remarks>
        /// see: http://www.scottlogic.co.uk/blog/colin/2009/09/helpful-extension-methods-for-show-hide-animations-in-silverlight/
        /// </remarks>
        public static void Hide(this FrameworkElement element)
        {
            string animationName = element.Name + "HideAnim";

            // check for presence of a hide animation
            Storyboard hideAnim = element.Resources[animationName] as Storyboard;
            if (hideAnim != null)
            {
                hideAnim.Begin();
            }
            else
            {
                element.Visibility = Visibility.Collapsed;
            }
        }
    }
}
